package com.wangbo.minio;

import cn.hutool.core.io.FileUtil;
import io.minio.MinioClient;
import io.minio.messages.Bucket;
import java.io.BufferedInputStream;
import java.util.Date;
import java.util.List;

public class TestMinioUtil {
    public static void main(String[] args) {
        MinioCache minioCache = new MinioCache();
        MinioClient minioClient = MinioClient.builder()
                .endpoint(minioCache.url)
                .credentials(minioCache.accessKey, minioCache.secretKey)
                .build();
        Date now = new Date();

        // bucket 是否存在
//        boolean exists = MinioUtil.bucketExists(minioClient, "test");
//        System.out.println(exists);

        // 遍历 buckets
//        List<Bucket> buckets = MinioUtil.getAllBuckets(minioClient);
//        for (Bucket bucket : buckets) {
//            System.out.println(bucket.name());
//        }

        // 添加 bucket
//        MinioUtil.makeBucket(minioClient, "wangbo");

        // 上传图片
//        BufferedInputStream inputStream = FileUtil.getInputStream("D:\\pic\\9358.jpg");
//        String url = MinioUtil.uploadFile(minioClient, "wangbo", "/data/" + String.format("%tF", now) + "/image/1.jpg", inputStream, "image/jpeg", 7);
//        System.out.println(url);

        // 获取 object
//        byte[] bytes = MinioUtil.getObject(minioClient, "wangbo", "/data/2022-01-18/image/1.jpg");
//        FileUtil.writeBytes(bytes, "D:\\download\\1.jpg");
    }

}
